package com.company.admin.configuration;

import com.alibaba.druid.pool.DruidDataSource;
import com.company.admin.config.DruidConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * @author 赵成林
 * @date 2019/2/16 19:27
 */
@Configuration
public class DruidConfiguration {

    @Autowired
    private DruidConfig druidConfig;

    @Bean
    public DataSource getDataSource(){
        DruidDataSource druidDataSource = new DruidDataSource();
        druidDataSource.setUrl(druidConfig.getUrl());
        druidDataSource.setPassword(druidConfig.getPassword());
//        druidDataSource.setName(druidConfig.getUsername());
        druidDataSource.setUsername(druidConfig.getUsername());
//        System.out.println(druidDataSource.getName());
//        System.out.println(druidDataSource.getPassword());
        return druidDataSource;
    }
}
